﻿<Page x:Class="Wokhan.WindowsFirewallNotifier.Console.UI.Pages.Monitor"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:LineChart="clr-namespace:Wokhan.WindowsFirewallNotifier.Console.UI.Controls"
      mc:Ignorable="d" 
      DataContext="{Binding RelativeSource={RelativeSource Self}}" 
      d:DesignHeight="400" d:DesignWidth="700" 
      x:Name="MonitorPage"
      Title="Monitor">
    <DockPanel>
        <Border Background="#FFFF7B7B" Style="{StaticResource NonAdminPanel}">
            <WrapPanel>
                <Label Content="Information provided here might be inaccurate for non-admin users." />
                <Button x:Name="btnRestartAdmin" Click="btnRestartAdmin_Click">
                    <Grid>
                        <Path Height="16" HorizontalAlignment="Left" Stretch="Uniform" Fill="#FF5353F7" Data="{StaticResource Image_Shield}" />
                        <Label Margin="20,0,0,0" Padding="0" Content="restart as admin" />
                    </Grid>
                </Button>
            </WrapPanel>
        </Border>
        <Border Style="{StaticResource ToolBarPanel}">
            <Grid>
                <WrapPanel HorizontalAlignment="Left">
                    <ToggleButton IsChecked="{Binding IsTrackingEnabled}">
                        <Grid>
                            <Path HorizontalAlignment="Left" Width="10" Stretch="Uniform" Fill="Green">
                                <Path.Style>
                                    <Style TargetType="Path">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsTrackingEnabled, FallbackValue=True}" Value="True">
                                                <Setter Property="Data" Value="{StaticResource Image_Stop}" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding IsTrackingEnabled}" Value="False">
                                                <Setter Property="Data" Value="{StaticResource Image_Start}" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Path.Style>
                            </Path>
                            <TextBlock Margin="15,0,0,0" Text="Tracking" />
                        </Grid>
                    </ToggleButton>
                    <ToggleButton IsChecked="{Binding IsSingleMode}">
                        <Grid>
                            <Path Fill="Blue" Data="{StaticResource Image_SingleMode}" />
                            <TextBlock Margin="20,0,0,0" Text="Single-item mode" />
                        </Grid>
                    </ToggleButton>
                    <TextBlock VerticalAlignment="Center" Text="{Binding Series.Count, StringFormat='Active connection(s): {0}', FallbackValue='No active connection'}" />
                </WrapPanel>
                <WrapPanel HorizontalAlignment="Right">
                    <Border BorderBrush="White" Background="White" BorderThickness="0" CornerRadius="8" Padding="5,2" Margin="0,0,5,0">
                        <WrapPanel>
                            <Path Fill="#FFA2A2FF" Data="{StaticResource Image_UpdateRate}"/>
                            <Label Margin="4,0" Content="Update rate:" />
                            <ComboBox IsEditable="False" Width="70" ItemsSource="{Binding Intervals, StringFormat='\{0\}s'}" SelectedValue="{Binding Interval}" />
                        </WrapPanel>
                    </Border>
                    <ToggleButton x:Name="btnHelp">
                        <Path Fill="Chocolate" Data="{StaticResource Image_Help}"/>
                    </ToggleButton>
                </WrapPanel>
            </Grid>
        </Border>
        <Grid>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="150" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <DataGrid BorderThickness="0" ColumnWidth="*" GridLinesVisibility="None" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" SelectionMode="Single" SelectionUnit="FullRow" Background="Transparent" ItemsSource="{Binding GroupedConnections}" AutoGenerateColumns="False" HeadersVisibility="Column">
                    <DataGrid.Resources>
                        <Style TargetType="DataGridRow">
                            <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                        </Style>
                    </DataGrid.Resources>
                    <DataGrid.Columns>
                        <DataGridTemplateColumn SortMemberPath="Name" Header="Process">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Path Grid.Column="0" ToolTip="{Binding LastError}" Height="16" Stretch="Uniform" Fill="OrangeRed" Data="F1 M 58.5832,55.4172L 17.4169,55.4171C 15.5619,53.5621 15.5619,50.5546 17.4168,48.6996L 35.201,15.8402C 37.056,13.9852 40.0635,13.9852 41.9185,15.8402L 58.5832,48.6997C 60.4382,50.5546 60.4382,53.5622 58.5832,55.4172 Z M 34.0417,25.7292L 36.0208,41.9584L 39.9791,41.9583L 41.9583,25.7292L 34.0417,25.7292 Z M 38,44.3333C 36.2511,44.3333 34.8333,45.7511 34.8333,47.5C 34.8333,49.2489 36.2511,50.6667 38,50.6667C 39.7489,50.6667 41.1666,49.2489 41.1666,47.5C 41.1666,45.7511 39.7489,44.3333 38,44.3333 Z ">
                                            <Path.Style>
                                                <Style TargetType="Path">
                                                    <Setter Property="Visibility" Value="Collapsed"/>
                                                    <Style.Triggers>
                                                        <DataTrigger Binding="{Binding IsAccessDenied}" Value="True">
                                                            <Setter Property="Visibility" Value="Visible" />
                                                        </DataTrigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </Path.Style>
                                        </Path>
                                        <Image Source="{Binding Icon}" Width="16" Stretch="Uniform" Margin="2,0" />
                                        <TextBlock Foreground="{Binding Brush}" Text="{Binding Name}" />
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Binding="{Binding Count,StringFormat='({0})'}" Header="Connections"/>
                        <DataGridTextColumn Binding="{Binding LastOut}" Header="Up" />
                        <DataGridTextColumn Binding="{Binding LastIn}" Header="Down" />
                    </DataGrid.Columns>
                </DataGrid>
                <GridSplitter Grid.Row="1" Height="2" Background="{DynamicResource AccentColorBrush}" HorizontalAlignment="Stretch" />
                <LineChart:LineChart Grid.Row="2" x:Name="chart" XAxeType="DateTime" DataSeries="{Binding Series, ElementName=MonitorPage}" />
            </Grid>
            <Border Style="{StaticResource InfoBlock}">
                <TextBlock>This screen displays all active connections on this computer, updated every second (by default).
Closed connections (in orange) will remain displayed a few seconds before disappearing.</TextBlock>
            </Border>
        </Grid>
    </DockPanel>
</Page>
